package com.scy.java.Array;

import java.util.Arrays;

public class BubbleSort {
    public static void main(String[] args) {
        int[] arr = {9,3,621,5,78,54,7};
        //外层循环控制轮数，冒泡排序的轮数=元素个数-1
        for (int i = 0; i < arr.length-1; i++) {
            for (int j = 0; j < arr.length-i-1; j++) {
                if (arr[j]>arr[j+1]){
                    //交换位置
                    int n = arr[j];
                    arr[j] = arr[j+1];
                    arr[j+1] = n;
                }
            }
        }
        System.out.println("排序后的数组为："+ Arrays.toString(arr));
    }
}
